﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.DiaoDongService;
using EHR.Common;

namespace CommunitySystem
{
    public partial class ZJZZRWindow : ChildWindow
    {
        DiaoDongServiceClient client = new DiaoDongServiceClient();
        ZJZZRModel Model = new ZJZZRModel();
        public ZJZZRWindow()
        {
            InitializeComponent();

            this.DataContext = Model;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(Model.ZCDWID.ToString()))
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择转出单位!");
                return;
            }
            if (string.IsNullOrEmpty(Model.ZRDWID.ToString()))
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择转入单位!");
                return;
            }
            if (string.IsNullOrEmpty(Model.ZRRQ))
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择转入日期!");
                return;
            }
            if (string.IsNullOrEmpty(Model.WH))
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("文号不能为空!");
                return;
            }
            Model.CreateDate = DateTime.Now.ToString();
            Model.CreateUser = Session.LoginUser.LoginName;
            client.AddZJZZRCompleted += new EventHandler<AddZJZZRCompletedEventArgs>(client_AddZJZZRCompleted);
            client.AddZJZZRAsync(Model);
        }

        void client_AddZJZZRCompleted(object sender, AddZJZZRCompletedEventArgs e)
        {
            if (e.Result)
                SilverlightMessageBoxLibrary.Message.InfoMessage("添加成功!");
            else SilverlightMessageBoxLibrary.Message.InfoMessage("添加失败!");

            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}

